/**
 * pageTitle - Directive for set Page title - mata title
 */
class pageTitle{
    constructor($rootScope, $timeout) {
        this.$rootScope = $rootScope;
        this.$timeout   = $timeout;
        this.restrict   = 'A';
    }

    link(scope, element) {

        this.$rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {

            var title = 'YiBa | 后台管理';

            if (toState.data && toState.data.pageTitle) {
                title = 'YiBa | ' + toState.data.pageTitle;
            }
            
            this.$timeout( () => {
                element.text(title);
            });
        });

    }
}

pageTitle.$inject = ['$rootScope', '$timeout'];

export default pageTitle;